//加载当前商品的信息

//图片的点击事件
$('.detail-show .thumb-show ').on('mouseover', 'img', function () {
    var src = $(this).attr('src');
    $('.detail-show .big-pic ').attr('src', src);
});

//加入购物车的事件
$('#btn-add-cart').click(() => {
    //商品的ID 添加
    obajax.post(
        '/api/user/cart',
        {goodsId: goodsId},
        (result) => {
            //提示
            alert("加入购物车成功！");
        },
        (result)=>{
            alert(result.msg);
            //失败
            if(result.code == 5){
                window.location.href="/user/login";
            }
        }
    )
});

function loadGoods(id) {
    //ajax
    obajax.get(
        '/api/goods/' + id,
        {},
        (result) => {
            //回显商品信息 result.data
            var goods = result.data;
            $('.detail-goods .detail-info .item-title').text(goods.name);
            $('.detail-goods .item-price .now').text(goods.price);
            $('.detail-goods .item-price .dft').text(goods.markPrice);
            $('.detail-goods .item-data .col-4 .txt-theme').text(goods.dscp);
            $('.dd .stock').text("库存：" + goods.count);
            $('.dd .chose-img li a').text(goods.author);
            $('.dd .chose-common li a').text(goods.press);

            //回显商品的事件
            $('.origin-show .big-pic ').attr('src', "/upload/" + goods.pics[0].url);
            var html = '';
            $.each(goods.pics, (index, pic) => {
                html += '<span class="item"><img class="s-pic" src="/upload/' + pic.url + '"/></span>';
            });
            $('.detail-show .thumb-show ').html(html);
        }
    );
}

